package problems.contest;

/**
 * 第 341 场周赛
 * <p>https://leetcode.cn/contest/weekly-contest-341</p>
 *
 * @author dubulingbo, 2023-04-16 10:26.
 */
public class WCT341 {
    /**
     * T1.
     */
    public int[] rowAndMaximumOnes(int[][] mat) {
        int row = -1;
        int cnt = -1;

        for (int i = 0; i < mat.length; ++i) {
            int c = 0;
            for (int j = 0; j < mat[i].length; ++j) {
                if (mat[i][j] == 1) ++c;
            }

            if (c > cnt) {
                cnt = c;
                row = i;
            }
        }

        return new int[]{row, cnt};
    }

    /**
     * T2.
     */
    public int maxDivScore(int[] nums, int[] divisors) {
        int n = nums.length;

        int score = -1;
        int ret = Integer.MAX_VALUE;
        for (int d : divisors) {
            int s = 0;
            for (int i = 0; i < n; ++i) {
                if (nums[i] % d == 0) {
                    ++s;
                }
            }

            if (s > score) {
                score = s;
                ret = d;
            } else if (s == score) {
                ret = Math.min(ret, d);
            }
        }

        return ret;
    }

    /**
     * T3.
     */
    public int addMinimum(String word) {
        int cnt = 0;
        char[] chs = word.toCharArray();
        int n = chs.length;
        for (int i = 0; i < n; ++i) {
            if (chs[i] == 'a') {
                if (i + 1 < n && chs[i + 1] == 'b') {
                    // ab
                    ++i;
                    if (i + 1 < n && chs[i + 1] == 'c') {
                        // abc
                        ++i;
                    } else {
                        ++cnt;
                    }
                } else if (i + 1 < n && chs[i + 1] == 'c') {
                    // ac
                    ++i;
                    ++cnt;
                } else {
                    cnt += 2;
                }
            } else if (chs[i] == 'b') {
                ++cnt;
                if (i + 1 < n && chs[i + 1] == 'c') {
                    // bc
                    ++i;
                } else {
                    ++cnt;
                }
            } else {
                cnt += 2;
            }
        }
        return cnt;
    }

    /**
     * T4.
     */
//    public int minimumTotalPrice(int n, int[][] edges, int[] price, int[][] trips) {
//
//    }
}
